<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>{$data.name}</title>
    <link rel="stylesheet" href="__STATIC__assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="__STATIC__assets/module/admin.css?v=318"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        /** 数据表格中的select尺寸调整 */
        .layui-table-view .layui-table-cell .layui-select-title .layui-input {
            height: 28px;
            line-height: 28px;
        }

        .layui-table-view [lay-size="lg"] .layui-table-cell .layui-select-title .layui-input {
            height: 40px;
            line-height: 40px;
        }

        .layui-table-view [lay-size="lg"] .layui-table-cell .layui-select-title .layui-input {
            height: 40px;
            line-height: 40px;
        }

        .layui-table-view [lay-size="sm"] .layui-table-cell .layui-select-title .layui-input {
            height: 20px;
            line-height: 20px;
        }

        .layui-table-view [lay-size="sm"] .layui-table-cell .layui-btn-xs {
            height: 18px;
            line-height: 18px;
        }
    </style>
</head>
<body onscroll="layui.admin.hideFixedEl();">
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格工具栏 -->
            <form class="layui-form toolbar table-tool-mini">
                <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label w-auto">套餐名称:</label>
                        <div class="layui-input-inline">
                            <input name="taocan_name" class="layui-input" type="text" placeholder="请输入套餐名称"/>
                        </div></div>
                    <div class="layui-inline" style="padding-right: 0px;">
                        <button class="layui-btn icon-btn" lay-filter="tbBasicTbSearch" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button id="tbBasicExportBtn" class="layui-btn icon-btn" type="button">
                            <i class="layui-icon">&#xe67d;</i>导出
                        </button>
                        <button class="layui-btn icon-btn" id="shanghtianj" type="button">
                            <i class="layui-icon">&#xe624;</i>添加
                        </button>
                       
                    </div>
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="tbBasicTable" lay-filter="tbBasicTable"></table>
        </div>
    </div>
  
</div>
<!-- 固定底部按钮 -->
<script type="text/html" id="dialogEditDialog1">
    <form id="dialogEditForm1" lay-filter="dialogEditForm1" class="layui-form model-form no-padding">
        <input name="id" type="hidden"/>
	
        <div class="model-form-body" style="max-height: 430px;">
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐名称:</label>
                <div class="layui-input-block">
                    <input name="taocan_name" placeholder="套餐名称" class="layui-input"
                           lay-verify="required" required />
                </div>
            </div> 
            
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐价格:</label>
                <div class="layui-input-block">
                     <input name="taocan_jiage" placeholder="套餐价格" class="layui-input"/>
                </div>
            </div> 
            
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐天数:</label>
                <div class="layui-input-block">
                     <input name="taocan_time" placeholder="套餐天数" class="layui-input"/>
                </div>
            </div> 
            
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐费率:</label>
                <div class="layui-input-block">
                     <input name="taocan_quanx1" placeholder="套餐费率" class="layui-input"/>
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐免挂权限:</label>
                <div class="layui-input-block">
                    <select name="taocan_quanx2" lay-verify="required" required>
                        <option value="1" >开启</option>
                        <option value="0" >关闭</option>
                    </select>
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐状态:</label>
                <div class="layui-input-block">
                    <select name="state" lay-verify="required" required>
                        <option value="1" >开启</option>
                        <option value="0" >关闭</option>
                    </select>
                </div>
            </div>
			
        </div>
        <div class="layui-form-item text-right model-form-footer">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="dialogEditSubmit1" lay-submit>保存</button>
        </div>
    </form>
</script>

<script type="text/html" id="shangh">
    <form id="dialogEditForm1" lay-filter="dialogEditForm1" class="layui-form model-form no-padding">
        <div class="model-form-body" style="max-height: 430px;">
        
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐名称:</label>
                <div class="layui-input-block">
                    <input name="taocan_name" placeholder="套餐名称" class="layui-input"
                           lay-verify="required" required />
                </div>
            </div> 
            
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐价格:</label>
                <div class="layui-input-block">
                     <input name="taocan_jiage" placeholder="套餐价格" class="layui-input"/>
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐天数:</label>
                <div class="layui-input-block">
                     <input name="taocan_time" placeholder="套餐天数" class="layui-input"/>
                </div>
            </div>
            
			<div class="layui-form-item">
                <label class="layui-form-label layui-form-required">套餐费率:</label>
                <div class="layui-input-block">
                    <input name="taocan_quanx1" placeholder="套餐费率" class="layui-input"
                           lay-verify="required" required/>
                </div>
            </div>
			
        </div>
        <div class="layui-form-item text-right model-form-footer">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="dialogEditSubmit1" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 表格操作列 -->
<script type="text/html" id="tbBasicTbBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
   
</script>

<!-- js部分 -->
<script type="text/javascript" src="__STATIC__assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="__STATIC__assets/js/common.js?v=318"></script>
<script>
    layui.use(['layer', 'form','admin','table', 'util', 'dropdown','baseTable'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var dropdown = layui.dropdown;
        var admin = layui.admin;
        /* 渲染表格 */
        var insTb = table.render({
            elem: '#tbBasicTable',
            url: "tablecard_list",
            page: true,
            limit: 15,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox',totalRowText: "合计" },
                {field: 'id', title: '排序', align: 'center',width:80},
                {field: 'taocan_name', title: '套餐名称', align: 'center',width:150},
                {field: 'taocan_jiage', title: '套餐价格', align: 'center',width:150},
                {field: 'taocan_quanx1', title: '套餐费率权限', align: 'center',width:150},
                {field: 'taocan_quanx2', title: '套餐免挂权限',minWidth:250,align:'center', templet: function (d) {
                    if(d.taocan_quanx2!=0){
                           return '<span class="layui-badge layui-badge-green">开启</span>';
                        }else{
                           return '<span class="layui-badge layui-badge-red">关闭</span>'
                        }
                    }
                },
                {field: 'taocan_time', title: '套餐天数',minWidth:150,align:'center', templet: function (d) {
                    if(d.taocan_time!=0){
                           return '<span class="layui-badge layui-badge-green">'+d.taocan_time+'天</span>';
                        }else{
                           return '<span class="layui-badge layui-badge-gray">永久</span>'
                        }
                    }
                },
                {field: 'state', title: '套餐状态',minWidth:150,align:'center', templet: function (d) {
                    if(d.state==1){
                           return '<span class="layui-badge layui-badge-green">开启</span>';
                        }else{
                           return '<span class="layui-badge layui-badge-red">关闭</span>'
                        }
                    }
                },
                {title: '操作', toolbar: '#tbBasicTbBar', align: 'center', minWidth: 120}
            ]]
        });

        /* 表格搜索 */
        form.on('submit(tbBasicTbSearch)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}});
            return false;
        });
        
        form.on('checkbox(a_all)', function(data){
           
           var a = data.elem.checked;
            if (a == true) {
                $(".game_id").prop("checked", false);
                form.render('checkbox');
            } 

         
        });  
        form.on('checkbox(b_all)', function(data){
           
           var a = data.elem.checked;
            if (a == true) {
                $(".game").prop("checked", false);
                form.render('checkbox');
            } 

         
        });  

        /* 表格工具条点击事件 */
        table.on('tool(tbBasicTable)', function (obj) {
            var data = obj.data; // 获得当前行数据
            if (obj.event === 'edit') { // 修改
                showMode(data);
            } else if (obj.event === 'del') { // 删除
                del(data);
            } 
            dropdown.hideAll();
        });
        
        function del(data){
            layer.confirm('确认要删除该套餐吗？', {
                shade: .1,
                skin: 'layui-layer-admin'
                }, function (i) {
                layer.close(i);
                    layer.load(2);
                    $.get('del_tablecard_list', {
                        id: data.id
                    }, function (res) {
                        layer.closeAll('loading');
                        if (res.code == 1) {
                            layer.msg(res.msg, {icon: 1});
                            insTb.reload({page: {curr: 1}});
                           
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'json');
                                
           });
        }
        
        function showMode(mData){
			admin.open({
                type: 1,
                title: "编辑",
				area: ['640px'],
                content: $('#dialogEditDialog1').html(),
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    form.val('dialogEditForm1',mData);
                    // 表单提交事件
                    form.on('submit(dialogEditSubmit1)', function (data) {
						var loadIndex = layer.load(2);
                        $.post('tablecard_save', data.field, function (res) {
                            layer.close(loadIndex);
                            if (1 == res.code) {                                
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload({page: {curr: 1}});
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'json');
                        return false;
                    });

                }
            });
		}

        // 导出excel
        $('#tbBasicExportBtn').click(function () {
            var checkRows = table.checkStatus('tbBasicTable');
            if (checkRows.data.length === 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });
        
        /* 商户添加 */
        $('#shanghtianj').click(function () {
			admin.open({
                type: 1,
                title: "添加",
				area: ['640px'],
                content: $('#shangh').html(),
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    // 表单提交事件
                    form.on('submit(dialogEditSubmit1)', function (data) {
						var loadIndex = layer.load(2);
                        $.post('tablecard_reg', data.field, function (res) {
                            layer.close(loadIndex);
                            if (1 == res.code) {                             
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload({page: {curr: 1}});
                                $("#dialogEditForm1")[0].reset();
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'json');
                        return false;
                    });

                }
            });
        });

    });
</script>
</body>
</html>